#include "DCClass.h"
// #include <iostream>

CDCRunClass* CDCRunClass::ms_pclsEnd = NULL;
unsigned int CDCRunClass::ms_nCount = 0;

CDCRunClass* CDCRunClass::Load(const char* pszClassName)
{
	for(CDCRunClass* _pclsCur = ms_pclsEnd;
		_pclsCur != NULL;
		_pclsCur = _pclsCur->m_pclsPrev)
	{
		if(strcmp(_pclsCur->m_pszClassName, pszClassName) == 0)
		{
			return _pclsCur;
		}
	}

	return NULL;
}

const char* CDCRunClass::GetClassName(int nID)
{
	CDCRunClass* _pCur = ms_pclsEnd;
	int _nID = 0;

	while(_nID < nID && _pCur != NULL)
	{
		_pCur = _pCur->m_pclsPrev;
		_nID++;
	}

	if(_nID == nID && _pCur != NULL)
		return _pCur->m_pszClassName;
	
	return NULL;
}

CDCBase* CDCRunClass::CreateClass(DCC_CREATE_PARAM)
{
	if(m_pfCreateClass == NULL)
	{
		return NULL;
	}

	CDCBase* _pClass = NULL;
	_pClass = (*m_pfCreateClass)(DCC_CREATE_PARAM_NAME);

	return _pClass;
}

void CDCRunClass::DeleteClass(CDCBase* pClass)
{
	if(m_pfDeleteClass == NULL)
		return;

	(*m_pfDeleteClass)(pClass);
}

SDCRunClassSave::SDCRunClassSave(CDCRunClass* pNewClass)
{
	pNewClass->m_pclsPrev = CDCRunClass::ms_pclsEnd;
	CDCRunClass::ms_pclsEnd = pNewClass;
	CDCRunClass::ms_nCount++;
}